﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Diagnostics;

namespace MediaCenter
{
    public partial class UseLed : Form
    {
        AmbientLight.LED led;
        Process p;

        public UseLed()
        {
            led = new AmbientLight.LED();
            InitializeComponent();
        }

        private void button9_Click(object sender, EventArgs e)
        {
            this.Dispose();
        }

        private void button8_Click(object sender, EventArgs e)
        {
            p = new Process();
            StartAmbi sa = new StartAmbi();
            try
            {
                button10.Enabled = true;
                led.SetColor(255, 255, 255);
                sa.runAmbilight(p);
            }
            catch (Exception)
            {
                button10.Enabled = false;
                showError();
            }
        }

        private void button1_Click(object sender, EventArgs e)
        {
            try
            {
                led.SetColor(255, 0, 0);
            }
            catch (Exception)
            {
                showError();
            }
        }

        private void button2_Click(object sender, EventArgs e)
        {
            try
            {
                led.SetColor(0, 255, 0);
            }
            catch (Exception)
            {
                showError();
            }
        }

        private void button5_Click(object sender, EventArgs e)
        {
            try
            {
                led.SetColor(0, 0, 255);
            }
            catch (Exception)
            {
                showError();
            }
        }

        private void button3_Click(object sender, EventArgs e)
        {
            try
            {
                led.SetColor(255, 0, 255);
            }
            catch (Exception)
            {
                showError();
            }
        }

        private void button4_Click(object sender, EventArgs e)
        {
            try
            {
                led.SetColor(255, 255, 0);
            }
            catch (Exception)
            {
                showError();
            }
        }

        private void button6_Click(object sender, EventArgs e)
        {
            try
            {
                led.SetColor(255, 255, 255);
            }
            catch (Exception)
            {
                showError();
            }
        }

        private void button10_Click(object sender, EventArgs e)
        {
            p.Kill();
        }

        private void UseLed_Load(object sender, EventArgs e)
        {

        }

        private void showError()
        {
            MessageBox.Show("Ambient light control not connected", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1);
        }
    }
}
